package cn.tedu.esspringboot.es;

import cn.tedu.esspringboot.entity.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentService {
    @Autowired
    private StudentRepository studentRepository;
    @Autowired
    private StudentSearcher searcher;

    //Repository模式查询
    //保存、修改
    public void save(Student student){
        studentRepository.save(student);//存入 es 服务器 stident 索引中
    }

    //删除
    public void delete(Long id){
        studentRepository.deleteById(id);
    }

    //查找
    public List<Student> findByName(String name, Pageable pageable){
        return studentRepository.findByName(name,pageable);
    }

    //查找
    public List<Student> findByNameOrBirthDate(String name, String birthDate){
        return studentRepository.findByNameOrBirthDate(name,birthDate);
    }

    //Criteria模式查询
    public List<Student> searchByBirthDate(String birthDate){
        return searcher.searchByBirthDate(birthDate);
    }

    //Criteria模式查询
    public List<Student> searchByBirthDate(String ge,String le,Pageable pageable){
        return searcher.searchByBirthDate(ge,le,pageable);
    }


}
